//
//  ListFoodTableViewCell.m
//  ZooNgonDoiOS
//
//  Created by Trung sound on 8/4/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "ListFoodTableViewCell.h"
#import "ZooUtil.h"

@implementation ListFoodTableViewCell
@synthesize lbNameFood = _lbNameFood;
@synthesize btnEat = _btnEat;
@synthesize btnLike = _btnLike;
@synthesize btnWishList = _btnWishList;
@synthesize btnDetailFood = _btnDetailFood;

#define AVATAR_FOOD_SIZE 70
#define IMG_LIKE_SIZE 24
#define BUTTON_HEIGHT 45
#define BUTTON_WIDTH 74

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _vInfoFood = [[UIImageView alloc]init];
        _vImgFood =  [[UIImageView alloc]init];
        _vImgLike =  [[UIImageView alloc]init];
        _vInfoFood.frame = CGRectMake(10, 5, 299, 81);
        
        [_vInfoFood setImage:[UIImage imageNamed:IMG_LISTFOOD_BACKGROUND]];
        
        _vImgFood.frame = CGRectMake(5, 5, AVATAR_FOOD_SIZE, AVATAR_FOOD_SIZE);
        [_vImgFood setImage:[UIImage imageNamed:@"food1.png"]];
        
        _lbNameFood = [[UILabel alloc]initWithFrame:CGRectMake(AVATAR_FOOD_SIZE+10, 5, 210, 20)];
        [_lbNameFood setFont:[UIFont boldSystemFontOfSize:15]];
        [_lbNameFood setBackgroundColor:[UIColor clearColor]];
        
        _vImgLike.frame = CGRectMake(AVATAR_FOOD_SIZE+10, 35, IMG_LIKE_SIZE, IMG_LIKE_SIZE);
        [_vImgLike setImage:[UIImage imageNamed:IMG_LIKE]];
        
        _lbPersonLike = [[UILabel alloc]initWithFrame:CGRectMake(AVATAR_FOOD_SIZE+IMG_LIKE_SIZE+12, 32, 100, 30)];
        [_lbPersonLike setFont:[UIFont systemFontOfSize:16]];
        [_lbPersonLike setBackgroundColor:[UIColor clearColor]];
        [_lbPersonLike setText:@"+15"];
        [_lbPersonLike setTextAlignment:UITextAlignmentLeft];
        [_lbPersonLike setTextColor:[ZooUtil getColorFromHexa:@"2e8193" alpha:1.0]];
        
        _lbCost = [[UILabel alloc]initWithFrame:CGRectMake(215, 30, 75, 30)];
        [_lbCost setFont:[UIFont systemFontOfSize:21]];
        [_lbCost setText:@"35K"];
        [_lbCost setTextColor:[ZooUtil getColorFromHexa:@"ba3129" alpha:1.0]];
        
        [_vInfoFood addSubview:_lbNameFood];
        [_vInfoFood addSubview:_lbPersonLike];
        [_vInfoFood addSubview:_vImgFood];
        [_vInfoFood addSubview:_vImgLike];
        [_vInfoFood addSubview:_lbCost];
        
        _btnEat = [[UIButton alloc]initWithFrame:CGRectMake(10, 88, BUTTON_WIDTH, BUTTON_HEIGHT)];
        [self setupButton:_btnEat background:IMG_LISTFOOD_BTN_BACKGROUND viewIcon:_vImgEat nameIcon:IMG_BTN_LISTFOOD_EAT label:_lbEat labelContent:@"Đã ăn"];
        
        _btnWishList = [[UIButton alloc]initWithFrame:CGRectMake(10 + BUTTON_WIDTH+1, 88, BUTTON_WIDTH, BUTTON_HEIGHT)];
        [self setupButton:_btnWishList background:IMG_LISTFOOD_BTN_BACKGROUND viewIcon:_vImgWishList nameIcon:IMG_BTN_LISTFOOD_WISHLIST label:_lbWishList labelContent:@"Thêm"];
        
        _btnLike = [[UIButton alloc]initWithFrame:CGRectMake(10 + (BUTTON_WIDTH+1)*2, 88, BUTTON_WIDTH, BUTTON_HEIGHT)];
        [self setupButton:_btnLike background:IMG_LISTFOOD_BTN_BACKGROUND viewIcon:_vImgLike nameIcon:IMG_BTN_LISTFOOD_LIKE label:_lbLike labelContent:@"Thích"];
        
        
        _btnDetailFood = [[UIButton alloc]initWithFrame:CGRectMake(10 + (BUTTON_WIDTH+1)*3, 88, BUTTON_WIDTH, BUTTON_HEIGHT)];
        [self setupButton:_btnDetailFood background:IMG_LISTFOOD_BTN_BACKGROUND viewIcon:_vImgDetailFood nameIcon:IMG_BTN_LISTFOOD_DETAIL label:_lbDetailFood labelContent:@"Chi tiết"];

//        [_btnDetailFood addTarget:self action:@selector(detailFoodButtonCicked:) forControlEvents:UIControlEventTouchUpInside];
  
        
        [self addSubview:_vInfoFood];
        [self addSubview:_btnEat];
        [self addSubview:_btnLike];
        [self addSubview:_btnWishList];
        [self addSubview:_btnDetailFood];
        
        [_vInfoFood release];
        [_vImgFood release];
        [_vImgLike release];
        [_lbPersonLike release];
        [_lbNameFood release];
        [_lbCost release];
    }
    return self;
}


- (void)setupButton:(UIButton *)pButton background:(NSString *)pNameBackground viewIcon:(UIImageView *)pViewIcon nameIcon:(NSString *)pNameIcon label:(UILabel *)pLabel labelContent:(NSString *)pContent {
    [pButton setBackgroundImage:[UIImage imageNamed:pNameBackground] forState:UIControlStateNormal];
    pViewIcon = [[UIImageView alloc]initWithFrame:CGRectMake(25, 5, 24, 24)];
    [pViewIcon setImage:[UIImage imageNamed:pNameIcon]];
    pLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, BUTTON_WIDTH, 15)];
    
    [pLabel setBackgroundColor:[UIColor clearColor]];
    [pLabel setFont:[UIFont systemFontOfSize:15]];
    [pLabel setText:pContent];
    [pLabel setTextAlignment:UITextAlignmentCenter];
    [pLabel setTextColor:[UIColor whiteColor]];
    [pButton addSubview:pViewIcon];
    [pButton addSubview:pLabel];
    
    [pViewIcon release];
    [pLabel release];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
